<template>
  <view class="part-card">
    <image src="../../../../static/logo.jpg" class="part-image" mode="aspectFill"></image>
    <view class="part-content">
      <view class="part-header">
        <text class="part-name">{{ props?.partName }}</text>
      </view>
      <view class="part-details">
        <view class="detail-item">
          <text class="label">备件编码：</text>
          <text class="value">{{ props?.partCode }}</text>
        </view>
        <view class="detail-item">
          <text class="label">领取数量：</text>
          <text class="value">{{ props?.obtainQuantity }}</text>
        </view>
        <view class="detail-item">
          <text class="label">单件备价：</text>
          <text class="value price">{{
            props?.newPartPrice ? '¥' + props?.newPartPrice : '暂无'
          }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import { defineProps } from 'vue'
import { getValueName } from '@/utils/nameValues'
import { onShow } from '@dcloudio/uni-app'
onShow(() => {
  // const {  productMajorCategoryDesc,
  //   productMiddleCategoryDesc,
  //   productMinorCategoryDesc} = props
  // console.log('onShow',productMajorCategoryDesc,
  //   productMiddleCategoryDesc,
  //   productMinorCategoryDesc)
})
const props = defineProps({
  partCode: String,
  partName: String,
  productMajorCategoryDesc: String,
  productMiddleCategoryDesc: String,
  productMinorCategoryDesc: String,
  address: String,
  contactPhone: String,
  imageSrc: String,

  newPartPrice: String,
  obtainQuantity: String,
  woNo: String,
  woPartId: String,
  woPartStatus: String,
})

const safeImageSrc = ref(props.imageSrc || 'default-image.png')

watch(
  () => props.imageSrc,
  (newVal) => {
    safeImageSrc.value = newVal || 'default-image.png'
  },
)
</script>

<style lang="scss" scoped>
.part-card {
  display: flex;
  background: #ffffff;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.part-image {
  width: 120rpx;
  height: 120rpx;
  border-radius: 8px;
  background: #f5f5f5;
  object-fit: cover;
}

.part-content {
  flex: 1;
  margin-left: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.part-header {
  margin-bottom: 12px;
}

.part-name {
  font-size: 28rpx;
  font-weight: 500;
  color: #333;
  line-height: 1.4;
}

.part-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-item {
  display: flex;
  align-items: center;
  font-size: 24rpx;

  .label {
    color: #999;
    min-width: 120rpx;
  }

  .value {
    color: #666;

    &.price {
      color: #60cd92;
      font-weight: 500;
    }
  }
}
</style>
